package com.audaque.springboot.foshanupload.web.amqpdemo.binding;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class DelayBindingConfig {


    @Bean
    public FanoutExchange delayExchange() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        FanoutExchange topicExchange = new FanoutExchange("delay_exchange", true, false, args);
        //延时
        topicExchange.setDelayed(true);
        return topicExchange;
    }

    @Bean
    public Queue queue() {
        Queue queue = new Queue("delay_queue");
        return queue;
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(delayExchange());
    }
}

